"use client"; import { GlobalNoticeRep, updateGlobalNoticeApi, updateUserNoticeApi } from "@/api/home"; import Box from "@/components/Box"; import Empty from "@/components/Empty"; import { timeFormat } from "@/utils/methods"; import { Badge, Collapse } from "antd-mobile"; import { useLocale } from "next-intl"; import { useState } from "react"; import style from "./style.module.scss"; interface Props { data: GlobalNoticeRep[]; type: "system" | "user"; } const SystemMessage = (props: Props) => { const { data, type } = props; const locale = useLocale(); const [noticesData, setNoticesData] = useState(data); const collapseChange = (active: string | null) => { if (!active) return; const isRead = noticesData.find((item) => item.id === +active)?.is_read; if (isRead) return; const newNotices = noticesData.map((item) => { if (item.id === +active && !item.is_read) { return { ...item, is_read: true }; } else { return item; } }); if (type === "system") { updateGlobalNoticeApi(+active).then((r) => {}); } else { updateUserNoticeApi(+active); } setNoticesData(newNotices); }; if (!noticesData.length) return ; return (
{noticesData.map((notice, index) => (
{notice.content?.title}

{notice.send_time ? timeFormat(notice.send_time!, locale) : timeFormat(notice.send_user_time!, locale)}

} >

{notice.content?.text}

{notice.content?.word}

))}
); }; export default SystemMessage;